package cn.iocoder.yudao.module.system.dal.mysql.messageType;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.SortingField;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.system.dal.dataobject.messageType.MessageTypeDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.system.controller.admin.messageType.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 站内信类型 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface MessageTypeMapper extends BaseMapperX<MessageTypeDO> {

    default PageResult<MessageTypeDO> selectPage(MessageTypePageReqVO reqVO) {
        List<SortingField> sortingFields=new ArrayList<>();
        SortingField sortingField=new SortingField();
        sortingField.setField("top");
        sortingField.setOrder("desc");
        sortingFields.add(sortingField);
        sortingField=new SortingField();
        sortingField.setField("update_time");
        sortingField.setOrder("desc");
        sortingFields.add(sortingField);
        reqVO.setSortingFields(sortingFields);
        return selectPage(reqVO, new LambdaQueryWrapperX<MessageTypeDO>()
                .likeIfPresent(MessageTypeDO::getName, reqVO.getName())
                .eqIfPresent(MessageTypeDO::getNum, reqVO.getNum())
                .betweenIfPresent(MessageTypeDO::getPublishTime, reqVO.getBeginPublishTime(), reqVO.getEndPublishTime())
                .eqIfPresent(MessageTypeDO::getStatus, reqVO.getStatus())
                .eqIfPresent(MessageTypeDO::getTop, reqVO.getTop())
                .betweenIfPresent(MessageTypeDO::getUpdateTime, reqVO.getBeginUpdateTime(), reqVO.getEndUpdateTime()));

    }

    default List<MessageTypeDO> selectList(MessageTypeExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<MessageTypeDO>()
                .likeIfPresent(MessageTypeDO::getName, reqVO.getName())
                .eqIfPresent(MessageTypeDO::getNum, reqVO.getNum())
                .betweenIfPresent(MessageTypeDO::getPublishTime, reqVO.getBeginPublishTime(), reqVO.getEndPublishTime())
                .eqIfPresent(MessageTypeDO::getStatus, reqVO.getStatus())
                .eqIfPresent(MessageTypeDO::getTop, reqVO.getTop())
                .betweenIfPresent(MessageTypeDO::getUpdateTime, reqVO.getBeginUpdateTime(), reqVO.getEndUpdateTime())
                .orderByDesc(MessageTypeDO::getId));
    }
    default List<MessageTypeDO> selectList() {
        return selectList(new LambdaQueryWrapperX<MessageTypeDO>().eqIfPresent(MessageTypeDO::getStatus,"1").orderByDesc(MessageTypeDO::getTop));
    }

    @TenantIgnore
    List<MessageTypeDO> recoveryMessageTypePage(IPage page, @Param("request") Map<String, Object> request );
    @TenantIgnore
   void updateBatchRecoveryMessageType( @Param("ids") List<Long> ids );

   long getMessageTypeMaxTop();

    void updateMessageTypeSort(@Param("list") List<MessageTypeDO> list);
}
